<?php 
$show_validator = true;
include TMPL_PATH.'public/header.phtml';
?>
<style type="text/css">
<!--
.content_box {
    background-color: #FFFFFF;
    border: 1px solid #DDDDDD;
    margin: 0 10px 10px 15px;
}
.f_r{float:right;}
img.operator {
    cursor: pointer;
    height: 12px;
    margin: 6px 6px 0;
    vertical-align: middle;
    width: 12px;
}
.grade li{ line-height:20px;}
-->
</style>
<script charset="UTF-8" src="/statics/js/artdialog/artDialog.min.js"></script>
<link href="/statics/js/artdialog/skin/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/statics/xheditor/xheditor-zh-cn.min.js"></script>
<script type="text/javascript"> 
<!--
	$(function(){
		$.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,width:'200',height:'50'}, function(){this.close();$(obj).focus();})}});
		<?php 
			//	if(isset($languageList) && $languageList):
			//		foreach ($languageList as $language_id => $language_name):
			?>
			//		var language_name = "<? echo $language_name; ?>";
			//		var language_id = <?php echo $language_id;?>;
//		$("#title_"+language_id).formValidator({onshow:"请输入货运公司"+language_name+"名称",onfocus:"请输入货运公司"+language_name+"名称",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"请输入货运公司"+language_name+"名称"});
		$("#title_1").formValidator({onshow:"请输入货运公司名称",onfocus:"请输入货运公司名称",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"请输入货运公司名称"});
		<?php 
			//	endforeach;
		//	endif;
		?>
		$("#name").formValidator({onshow:"请输入配送方式名称",onfocus:"请输入配送方式名称",oncorrect:"输入正确"}).regexValidator({regexp:"letter_l",datatype:"enum",onerror:"配送方式只能用小写字母"});
//		.ajaxValidator({
//		    type : "get",
//			url : "<?php echo U('shipping/shipping_checkname_ajax', 'sid='.$shipping['id']);?>",
//			data :"",
//			datatype : "html",
//			async:'false',
//			success : function(data){	
//	            if( data == "1" )
//				{
//	                return true;
//				}
//	            else
//				{
//	                return false;
//				}
//			},
//			buttons: $("#dosubmit"),
//			onerror : "配送方式已存在。",
//			onwait : "请稍候..."
//		});
	})
//-->
</script>
<div class="pad_10">
<div class="bk15"></div>
<div class="col-tab">
<ul class="tabBut cu-li">
<?php 
$langCount = 0;
if(isset($languageList) && $languageList){
		$langCount = count($languageList);
}
$langCount++;
?>
<?php 
	if(isset($languageList) && $languageList):
		$i = 0;
		foreach ($languageList as $language_id => $language_name):
			$i++;
	?>
<li id="tab_setting_<?php echo $i;?>" <?php if($i==1)echo 'class="on"';?> onclick="SwapTab('setting','on','',<?php echo $langCount;?>,<?php echo $i;?>);"><?php echo $language_name;?></li>
<?php 
		endforeach;
	endif;
	?>
<li id="tab_setting_<?php echo $langCount;?>" onclick="SwapTab('setting','on','',<?php echo $langCount;?>,<?php echo $langCount;?>);">基本选项</li>
</ul>
<form name="myform" action="__SELF__" method="post" id="myform">
<?php 
	if(isset($languageList) && $languageList):
		$i = 0;
		foreach ($languageList as $language_id => $language_name):
			$i++;
	?>
<div id="div_setting_<?php echo $i;?>" class="contentList pad-10 <?php if($i>1)echo 'hidden';?>">
	
	<table width="100%" class="table_form contentWrap">
		<tr>
			<th width="120">货运公司名称：</th> 
			<td><input type="text" id="title_<?php echo $language_id;?>" name="shipping[<?php echo $language_id;?>][title]" value="<?php echo isset($shipping['items'][$language_id]['title']) ? $shipping['items'][$language_id]['title'] : null;?>" class="input-text"/></td>
		</tr>
		<tr>
			<th>详细介绍：</th>
			<td><textarea name="shipping[<?php echo $language_id;?>][description]" style="width:50%;height:60px"><?php echo isset($shipping['items'][$language_id]['description']) ? $shipping['items'][$language_id]['description'] : null?></textarea></td>
		</tr>
        <tr>
            <th>时间描述：</th>
            <td><input type="text" id="title_<?php echo $language_id;?>" name="shipping[<?php echo $language_id;?>][day_or_time]" value="<?php echo isset($shipping['items'][$language_id]['day_or_time']) ? $shipping['items'][$language_id]['day_or_time'] : null;?>" class="input-text"/></td>
        </tr>
		</table>
</div>
<?php 
		endforeach;
	endif;
	?>
	<div id="div_setting_<?php echo $langCount;?>" class="contentList pad-10 hidden">
		<table width="100%" class="table_form contentWrap">
	<tr>
	<th width="120">配送方式名称：</th> 
	<td><input type="text" name="name" id="name" value="<?php echo isset($shipping['name']) ? $shipping['name'] : null;?>" class="input-text" <?php if($shipping['name']){echo "disabled";}?>/></td>
	</tr>
	<tr class="hidden">
		<th>类型：</th>
		<td>
			<label><input type="radio" onclick="radioselect(this)" <?php echo $shipping['type']==0 ? 'checked="checked"' : null;?> value="0" name="type">先收款后发货 </label>&nbsp;&nbsp;
			<label><input type="radio" onclick="radioselect(this)" <?php echo $shipping['type']==1 ? 'checked="checked"' : null;?> value="1" name="type">货到付款 </label><div class="infoShow">货到付款选择货到付款后顾客无需再选择支付方式</div>
		</td>
	</tr>
	<tr>
		<th>重量设置：</th>
		<td>首重重量 &nbsp;
						<select id="first_weight" name="first_weight">
							<option <?php echo $shipping['first_weight']==500 ? 'selected="selected"' : null;?> value="500" label="500克">500克</option>
							<option <?php echo $shipping['first_weight']==1000 ? 'selected="selected"' : null;?> value="1000" label="1千克">1千克</option>
							<option <?php echo $shipping['first_weight']==1200 ? 'selected="selected"' : null;?> value="1200" label="1.2千克">1.2千克</option>
							<option <?php echo $shipping['first_weight']==2000 ? 'selected="selected"' : null;?> value="2000" label="2千克">2千克</option>
							<option <?php echo $shipping['first_weight']==5000 ? 'selected="selected"' : null;?> value="5000" label="5千克">5千克</option>
							<option <?php echo $shipping['first_weight']==10000 ? 'selected="selected"' : null;?> value="10000" label="10千克">10千克</option>
							<option <?php echo $shipping['first_weight']==20000 ? 'selected="selected"' : null;?> value="20000" label="20千克">20千克</option>
							<option <?php echo $shipping['first_weight']==50000 ? 'selected="selected"' : null;?> value="50000" label="50千克">50千克</option>
						</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 续重单位 &nbsp;

						<select id="second_weight" name="second_weight">
							<option <?php echo $shipping['second_weight']==500 ? 'selected="selected"' : null;?> value="500" label="500克">500克</option>
							<option <?php echo $shipping['second_weight']==1000 ? 'selected="selected"' : null;?> value="1000" label="1千克">1千克</option>
							<option <?php echo $shipping['second_weight']==1200 ? 'selected="selected"' : null;?> value="1200" label="1.2千克">1.2千克</option>
							<option <?php echo $shipping['second_weight']==2000 ? 'selected="selected"' : null;?> value="2000" label="2千克">2千克</option>
							<option <?php echo $shipping['second_weight']==5000 ? 'selected="selected"' : null;?> value="5000" label="5千克">5千克</option>
							<option <?php echo $shipping['second_weight']==10000 ? 'selected="selected"' : null;?> value="10000" label="10千克">10千克</option>
							<option <?php echo $shipping['second_weight']==20000 ? 'selected="selected"' : null;?> value="20000" label="20千克">20千克</option>
							<option <?php echo $shipping['second_weight']==50000 ? 'selected="selected"' : null;?> value="50000" label="50千克">50千克</option>
						</select>
		</td>
	</tr>
	<tr class="hidden">
		<td></td>
		<td><label class="attr"><input type="checkbox" <?php echo $shipping['is_save_price']==1 ? 'checked="checked"' : null;?> onclick="protect_price(this)" id="is_save_price" value="1" name="is_save_price">支持物流保价</label></td>
	</tr>
	<tr id="protect">
			<th>保价设置：</th>
			<td> 费率&nbsp;<input type="text" class="input-text" size="5" value="<?php echo $shipping['save_rate']?>" id="save_rate" name="save_rate">%<label></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;最低保价费&nbsp;
			<input type="text" class="input-text" size="5" value="<?php echo $shipping['low_price']?>" id="low_price" name="low_price"><label>*该项必填且只允许填写数字金额</label></td>
	</tr>
	<tr>
		<th>地区费用类型：</th>
		<td><label class="attr"><input type="radio" onclick="set_area(0)" <?php echo $shipping['price_type']==0 ? 'checked="checked"' : null;?> value="0" name="price_type">统一设置</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<label class="attr"><input type="radio" onclick="set_area(1)" <?php echo $shipping['price_type']==1 ? 'checked="checked"' : null;?> id="price_type_1" value="1" name="price_type">指定配送地区和费用</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<!--<label class="attr"><input type="radio" onclick="set_area(2)" <?php echo $shipping['price_type']==2 ? 'checked="checked"' : null;?> id="price_type_2" value="2" name="price_type">按件数收费</label>--> </td>
	</tr>
	</table>
	<table id="set_delivery" class="table_form contentWrap">
		<colgroup><col width="120px">
		<col>
		</colgroup><tbody><tr style="" id="open_default">
			<td></td><td><input type="checkbox" <?php echo $shipping['open_default']==1 ? 'checked="checked"' : null;?> onclick="default_firce(this)" value="1" id="open_default_id" name="open_default">启用默认费用<span> 注意：未启用默认费用时，不在指定配送地区的顾客不能使用本配送方式下订单</span></td>
		</tr>
		<tr id="delivery" style="display: none;">
			<td></td><td> 
			首重费用 <input type="text" value="<?php echo $shipping['first_price']?>" name="first_price" style="width: 30px; display: none;" class="input-text">元 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
			续重费用 <input type="text" value="<?php echo $shipping['second_price']?>" name="second_price" class="input-text" style="width: 30px;display: none;">元&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	免费额度：<input type="text" name="free_price" id="free_price" value="<?php echo isset($shipping['free_price']) ? $shipping['free_price'] : null;?>" class="input-text"/>
	<div class="infoShow">当商品总额达到免费额度时免运费，<font color="red">当选择按件收费时，首重费用为每件费用，续重费用做废</font></div>
	</td>
		</tr>
		<tr style="" id="super_area">
					<th>支持的配送地区:</th><td>
                    <div id="area_list">
                    <?php if($shipping['area_groupid']):
                    	foreach ($shipping['area_groupid'] as $key => $val):
                    		if(empty($val)) continue;
                    ?>
                    	<div style="padding:6px; overflow:hidden; height:25px;" class="content_box">
                    	<span style="float:left;">配送地区 <input readonly="true" onclick="area_menu(this)" value="<?php echo $shipping['area'][$key];?>" name="area[]" class="input-text">
			 <input type="hidden" value="<?php echo $val;?>" name="area_groupid[]">
			首重费用 <input type="text"  value="<?php echo $shipping['firstprice'][$key];?>" name="firstprice[]" style="width: 30px;" class="input-text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
			续重费用 <input type="text" style="width: 30px;" value="<?php echo $shipping['secondprice'][$key];?>" name="secondprice[]" class="input-text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
			免费额度 <input type="text" style="width: 30px;" value="<?php echo $shipping['freeprice'][$key];?>" name="freeprice[]" class="input-text">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			是否按件收费：
			<select name="freenum[]">
				<option value="0" <?php if($shipping['freenum'][$key] == 0 || $shipping['freenum'][$key] == '') echo 'selected';?>>否
				<option value="1" <?php if(isset($shipping['freenum'][$key]) && $shipping['freenum'][$key] == 1) echo 'selected';?>>是
			</select>
			</span>
                    <a class="f_r" onclick="del_area(this)" href="javascript:void(0)"><img class="operator" src="../Public/images/icon_del.gif" alt="删除"></a>
			</div>
            <div style="clear:both;"></div>
							<?php 
									endforeach;
								endif;
							?>
			</div>
			<button onclick="add_area()" id="areaadd" type="button"><span class="panel-add">为指定的地区设置运费</span></button>
			</td>
		</tr>
	</tbody>
	</table>
	<table width="100%" class="table_form contentWrap">
	<tr>
	  <th width="120">排序：</th>
	  <td><input type="text" name="listorder" class="input-text" size="5" value="<?php echo $shipping['listorder']?>"/></td>
	</tr>
	<tr>
		<th>状态：</th>
		<td><label class="attr">
		<input type="radio" value="1" <?php echo $shipping['status']==1 ? 'checked="checked"' : null;?> name="status">启用</label>
		<label class="attr"><input type="radio" <?php echo $shipping['status']==0 ? 'checked="checked"' : null;?> value="0" name="status">关闭</label>
		</td>
	</tr>
	</table>
	</div>
 	<div class="bk15"></div>
  <input name="dosubmit" type="submit" class="button" value="提交" id="dosubmit" />
</form>
</div>
</div>

</body>
</html>
<script type='text/javascript'>
$(function(){
	set_area(<?php echo intval($shipping['price_type']);?>);
});
$('#protect,#protect input').css('display','<?php echo $shipping['is_save_price']==1 ? '' : 'none'?>');
$('#super_area,#super_area input').css('display','none');
function protect_price(obj)
{
	if(obj.checked)
	{
		$('#protect,#protect input').css('display','');
	}
	else
	{
		$('#protect,#protect input').css('display','none');
	}
}
function default_firce(obj)
{
	if(obj.checked)
	{
		$('#delivery,#delivery input').css('display','');
	}
	else
	{
		$('#delivery,#delivery input').css('display','none');
	}
}
function set_area(num)
{
	if(num==0)
	{
		 $('#open_default').css('display','none');
		 $('#delivery,#delivery input').css('display','');
		 $('#super_area,#super_area input').css('display','none');
		 $('#delivery th').html('配送费用:');
	}
	else if(num==1 || num==2)
	{
		$('#open_default').css('display','');
		$('#super_area').css('display','');
		$('#super_area,#super_area input').css('display','');
		$('#delivery th').html('');
		if(document.getElementById('open_default_id').checked)
		{
			 $('#delivery,#delivery input').css('display','');
		}
		else
		{
			$('#delivery,#delivery input').css('display','none');
		}
	}

}
//删改添加的地区
function del_area(obj)
{
    $(obj).parent().remove();
}
function add_area()
{			
	area_tpl = '<div style="padding:6px" class="content_box">';
	area_tpl += '<a class="f_r" onclick="del_area(this)" href="javascript:void(0)"><img class="operator" src="../Public/images/icon_del.gif" alt="删除"></a>';
	area_tpl += '配送地区 <input readonly="true"  onclick="area_menu(this)" name="area[]" class="input-text">';
	area_tpl += '<input type="hidden" value="" name="area_groupid[]">';
	area_tpl += '首重费用 <input type="text"  value="" name="firstprice[]" style="width: 30px;" class="input-text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ';
	area_tpl += '续重费用 <input type="text" value="" name="secondprice[]" style="width: 30px;" class="input-text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ';
	area_tpl += '免费额度 <input type="text" value="" name="freeprice[]" style="width: 30px;" class="input-text">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ';
	area_tpl += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;是否按件收费 <select name="freenum[]"><option value="0" >否<option value="1">是</select>';
	area_tpl += '</div>';
    $('#area_list').append(area_tpl);
}
function area_menu(obj)
{
	var tem='';
	art.dialog.load("<?php echo U('shipping/shipping_select_area_ajax');?>",{id:'select_area',title:'选择配送地区',width:"300px",height:"500px",yesFn:function(){
	$('#select_area input[leval=1]:checked').each(function(){tem+=$(this).parent().text()+';';});
	obj.value=tem.substring(0,tem.length-1);
	var value='';
	$('#select_area input:checked').each(function (){
		value += $(this).val()+';';
	});
	$(obj).next('input[type=hidden]').val(value);
	},noFn:function(){},initFn:function(){
		var values = ';'+$(obj).next('input[type=hidden]').val();
		$('#select_area input').each(function(){
			if(values.indexOf(';'+$(this).val()+';')!=-1)
			{
				$(this).attr('checked',true);
			}
		});
		$('#area_list').data('obj',obj);
	}},true);
}
//修改的时候设置默认
//修改改时初始化部分表单
</script>